import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']
plt.rcParams['axes.unicode_minus'] = False

data = {
    '类别': ['完成率', '占位'],
    '数值': [85, 15]
}
df = pd.DataFrame(data)

plt.figure(figsize=(6, 6))
colors = ['lightgreen', 'red']

#绘制饼图
plt.pie(df['数值'], autopct=None, startangle=-160, colors=colors)

#绘制中心圆覆盖饼图中心
centre_circle = plt.Circle((0, 0), 0.8, fc='white')
fig = plt.gcf()
fig.gca().add_artist(centre_circle)

total = np.sum(df['数值'])
completed_percentage = df['数值'][0] / total * 100

#添加文字
plt.text(0, 0, f'{completed_percentage:.0f}%\n目标完成率', ha='center', va='center', fontsize=30, weight='bold')

plt.axis('equal')
plt.tight_layout()

#plt.savefig('D:/python charm/01/可视化/第二章/图片/单值圆环图.png')

plt.show()